#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
pthread_cond_t cond;
pthread_mutex_t mtx;
void* actionA(void* args){
  while(1){
    printf("我是线程A\n");
    pthread_cond_signal(&cond);
    sleep(2);
  }
}
void* actionB(void* args){
  while(1){
    pthread_cond_wait(&cond, &mtx);
    printf("我是线程B\n");
    sleep(1);
  }
}
int main(){
  pthread_cond_init(&cond, NULL);
  pthread_mutex_init(&mtx, NULL);

  pthread_t tid_A;
  pthread_t tid_B;
  pthread_create(&tid_A, NULL, actionA, NULL);
  pthread_create(&tid_B, NULL, actionB, NULL);  

  pthread_join(tid_A, NULL);
  pthread_join(tid_B, NULL);

  pthread_cond_destroy(&cond);
  pthread_mutex_destroy(&mtx);
  return 0;
}
